package com.smart.parking.controller.backstage;

import com.smart.parking.config.Result;
import com.smart.parking.service.SpaceService;
import com.smart.parking.utils.PageUtils;
import com.smart.parking.vo.SpaceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 车位信息表
 *
 * @author ciyun
 */
@RestController
@RequestMapping("/space")
public class SpaceController {
    @Autowired
    private SpaceService spaceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = spaceService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 车位报修
     *
     * @param spaceId 车位id
     * @return {@link Result}
     */
    @GetMapping("/repairParking")
    public Result repairParking(@RequestParam("spaceId") Long spaceId){
        boolean flag = spaceService.repairParking(spaceId);
        if (flag) {
            return Result.ok("报修成功!");
        }
        return Result.error("报修失败!");
    }

    /**
     * 添加车位
     *
     * @param spaceVO 空间签证官
     * @return {@link Result}
     */
    @PostMapping("/addSpace")
    public Result addSpace(@RequestBody SpaceVO spaceVO){
        spaceService.addSpace(spaceVO);
        return Result.ok();
    }

    /**
     * 删除车位
     *
     * @param spaceId 空间id
     * @return {@link Result}
     */
    @DeleteMapping("/deleteSpace")
    public Result deleteSpace(@RequestParam("spaceId") Long spaceId){
        spaceService.deleteSpace(spaceId);
        return Result.ok();
    }

    /**
     * 批量删除车位
     *
     * @param spaceIds 空间id
     * @return {@link Result}
     */
    @DeleteMapping("/deleteSpaces")
    public Result deleteSpaces(@RequestBody Long[] spaceIds){
        spaceService.deleteSpaces(spaceIds);
        return Result.ok();
    }



}
